package com.zmm.myyimixian.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.zmm.myyimixian.R;
import com.zmm.myyimixian.bean.HomeBean;
import com.zmm.myyimixian.config.ConfigPath;

import java.util.List;

/**
 * Created by wencai2015 on 2016/10/21.
 */

public class MyHomeGvAdapter extends BaseAdapter {
    private List<HomeBean.CardListBean.MaterialBean> material;
    private Context context;

    public MyHomeGvAdapter(List<HomeBean.CardListBean.MaterialBean> material, Context context) {
        this.context = context;
        this.material = material;
    }

    @Override
    public int getCount() {
        return material.size();
    }

    @Override
    public Object getItem(int position) {
        return material.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HolderView holderView;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.mian_gridview_itme, parent, false);
            holderView = new HolderView(convertView);
            convertView.setTag(holderView);
        }else {
            holderView = (HolderView) convertView.getTag();
        }
        HomeBean.CardListBean.MaterialBean materialBean = material.get(position);
        Glide.with(context).load(ConfigPath.getLunBoPath(materialBean.getImage())).placeholder(R.mipmap.ic_my_head_pic).into(holderView.iv);
        return convertView;
    }

    static class HolderView {
        ImageView iv;

        public HolderView(View view) {
            this.iv = (ImageView) view.findViewById(R.id.main_gv_iv);
        }
    }
}
